//南航明珠商城-限时统一折扣管理.js

function search() {
	var startDate = $('#startDate').val();
	var endDate = $('#endDate').val();
	if ((startDate.length != 0 && startDate != '')
			&& (endDate.length != 0 && endDate != '')) {
		var startTime1 = startDate.slice(0, 4) + startDate.slice(5, 7)
				+ startDate.slice(8, 10);
		var endTime1 = endDate.slice(0, 4) + endDate.slice(5, 7)
				+ endDate.slice(8, 10);
		var timeValue1 = endTime1 - startTime1;
		if (timeValue1 < 0) {
			layer.alert("结束时间必须大于或等于开始时间!");
			return;
		}
	}
	document.getElementsByName("name")[0].value = document
			.getElementsByName("name")[0].value.trim();         
	$("#page").val("1");
	$("#search_form").submit();
}
function toIsEmpty() {
	$("#startDate").val("");
	$("#endDate").val("");
	document.getElementsByName("name")[0].value = "";
	document.getElementsByName("status")[0].value = "";
	document.getElementsByName("activeType")[0].value = "";
}
function addActive(title,url,w,h){
    var index = layer.open({
        type: 2,
        title: title,
        scrollbar: false,
        content: url,
        area: ['1000px', '600px']
    });
}
function editActive(id){
	var url=path+"/activity/to_edit_activity?id="+id;
    var index = layer.open({
        type: 2,
        title: "修改活动",
        scrollbar: false,
        content: url,
        area: ['1000px', '600px']
    });
}
function lookActive(id){
	var url=path+"/activity/look_activity?id="+id;
    var index = layer.open({
        type: 2,
        title: "查看活动",
        scrollbar: false,
        content: url,
        area: ['1000px', '600px']
    });
}
function auditActive(id){
	var url=path+"/activity/audit_activity?id="+id;
    var index = layer.open({
        type: 2,
        title: "审核活动",
        scrollbar: false,
        content: url,
        area: ['1000px', '600px']
    });
}

function deleteActive(id){
	layer.confirm("确定删除此活动?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		var url=path+"/activity/delete_activity?id="+id;
		$.ajax({
			url : url,
			cache : false,
			type : 'post',
			dataType : 'text',
			error : function() {
				layer.alert("操作失败！");
	       },
			success : function(data) {
			    if(data == "success"){
				    layer.msg('删除成功!',{icon:1,time:1000},function(){
				    	$("#search_form").submit();
				    });
			   }else if(data == "fail"){
				layer.alert("操作失败！");
			   } else {
				   layer.alert(data);
			   }
			},
			complete: function(XMLHttpRequest, textStatus) {
				layer.close(layer_load_window);
			}
		  })		
		});
}
function closeActive(id){
	layer.confirm("确定要关闭此活动?",function(){
		var url=path+"/activity/close_activity";
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		$.ajax({
			url : url,
			cache : false,
			type : 'post',
			dataType : 'text',
			data:{
				id:id,
			},
			error : function() {
				layer.alert("操作失败！");
	        },
			success : function(data) {
				var resultArr = data.split(",");
		   		if(resultArr[0] == "success"){
					layer.msg("关闭成功!",{icon:1,time:1000},function(){
				    	$("#search_form").submit();
					});
		   		}else if(resultArr[0] == "fail"){
		   			layer.alert(resultArr[1]);
		   		}else{
		   			layer.alert(data);
		   		}
			},
	        complete: function(XMLHttpRequest, textStatus) {
				layer.close(layer_load_window);
	        }
		  })		
		});
}